﻿using System.Collections;
using Sirenix.OdinInspector;
using UnityEngine;

namespace Gp.AI {
    [NodeTint(.45f, .35f, 0f)]
    public abstract class ConditionNode : BasicNode {
        [Input] public BaseNode last;

        [GUIColor(0, 1, 0)] [SerializeField] [Output(connectionType: ConnectionType.Override)]
        private BaseNode onTrue;

        [GUIColor(0, 0, 1)] [SerializeField] [Output(connectionType: ConnectionType.Override)]
        private BaseNode onFalse;

        public BaseNode FalseNode => GetOutputPort("onFalse").Connection?.node as BaseNode;
        public BaseNode TrueNode => GetOutputPort("onTrue").Connection?.node as BaseNode;
    }

    public abstract class ConditionEntry<T> : AINodeEntry<T> where T : ConditionNode {
        public ConditionEntry(T data) : base(data) { }

        public abstract bool Judge();

        public override IEnumerator Execute() {
            if (Judge()) {
                yield return ToNext(Data.TrueNode);
            }
            else {
                yield return ToNext(Data.FalseNode);
            }
        }
    }
}